package com.dcc.inventory.controller;

import com.dcc.inventory.entity.Auth;
import com.dcc.inventory.entity.User;
import com.dcc.inventory.servicesimp.UserServicesImp;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/api/user")
public class UserController {
    @Resource
    private UserServicesImp userServiceImp;


    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> login(String email, String upwd, HttpServletRequest request) {
        Map map = new HashMap();
         Auth userAuth =  userServiceImp.login(email, upwd, request);
        map.put("data", userAuth);
        return map;
    }

    @RequestMapping(value = "/authLogin", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> authLogin(String email, String upwd,HttpServletRequest request) {
        Map map = new HashMap();
        Auth user =  userServiceImp.simpleLogin(email, upwd,request);
        System.out.println(user);
        map.put("data", user);
        return map;
    }


}
